<?php

/**
 * 这是一个抽象类定义和使用的示例
 * User: ford
 * Date: 15-8-5
 * Time: 下午2:16
 */

/**
 * 定义一个抽象类Shape
 *
 * Class Shape
 */

include_once('tDebug.php');	//包含一个trait来测试一下

abstract class Shape {

	abstract protected function getArea();
	abstract protected function getPerimeter();

}

/**
 * 下面是一个子类的实现
 *
 * 没有属性，实现了父类的两个方法
 *
 * Class Triangle
 */
class Triangle extends Shape {
	use tDebug;

	//定义属性
	private $_sides = array();
	private $_perimeter = null;

	//构造函数
	function __construct($s0 = 0, $s1 = 0, $s2 = 0) {
		$this->_sides[] = $s0;
		$this->_sides[] = $s1;
		$this->_sides[] = $s2;

		$this->_perimeter = array_sum($this->_sides);
	}//构造函数结束

	//计算和返回面积
	public function getArea() {

		//计算并返回面积
		return (
			SQRT(
					($this->_perimeter/2) *
					($this->_perimeter/2 - $this->_sides[0]) *
					($this->_perimeter/2 - $this->_sides[1]) *
					($this->_perimeter/2 - $this->_sides[2])
			)
		);
	}


	public function getPerimeter() {
		return $this->_perimeter;
	}

	public function __toString() {
		$tmp = '面积:' . $this->getArea();
		$tmp .= '周长:' . $this->getPerimeter();

		return $tmp;
	}
}

$shape = new Triangle(2, 2, 3);
$shape->dumpObject();

echo $shape;